#include <libge/libge.h>
#include "Client.h"
#include "Material.h"

typedef struct BlockProps {
	int id;
	int data;
	int type;
	int solid;
	int collidable;
	int clickable;
	int biome_colored;
	const char* name;
	const char* texture;
	float specular;
	float height;
	float width;
} BlockProps;

BlockProps block_props[] = {
	{ 0, 0, BLOCK_TYPE_CUBE, 0, 0, 0, 0, "Air", "air", 0.0, 0.0, 0.0 },
	{ 1, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Stone", "stone", 0.0, 1.0, 1.0 },
	{ 2, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0x010000, "Grass", "grass_side", 0.0, 1.0, 1.0 },
	{ 2, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0x010000, "Grass", "grass_top", 0.0, 1.0, 1.0 },
	{ 3, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Dirt", "dirt", 0.0, 1.0, 1.0 },
	{ 4, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Stonebrick", "stonebrick", 0.0, 1.0, 1.0 },
	{ 5, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Oak Wood Planks", "wood", 0.0, 1.0, 1.0 },
	{ 5, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Spruce Wood Planks", "wood_spruce", 0.0, 1.0, 1.0 },
	{ 5, 2, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Birch Wood Planks", "wood_birch", 0.0, 1.0, 1.0 },
	{ 5, 3, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Jungle Wood Planks", "wood_jungle", 0.0, 1.0, 1.0 },
	{ 6, 0, BLOCK_TYPE_CUBE, 0, 0, 1, 0, "Oak Sapling", "sapling", 0.0, 1.0, 1.0 },
	{ 6, 1, BLOCK_TYPE_CUBE, 0, 0, 1, 0, "Spruce Sapling", "sapling_spruce", 0.0, 1.0, 1.0 },
	{ 6, 2, BLOCK_TYPE_CUBE, 0, 0, 1, 0, "Birch Sapling", "sapling_birch", 0.0, 1.0, 1.0 },
	{ 6, 3, BLOCK_TYPE_CUBE, 0, 0, 1, 0, "Jungle Sapling", "sapling_jungle", 0.0, 1.0, 1.0 },
	{ 7, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Bedrock", "bedrock", 0.0, 1.0, 1.0 },
	{ 8, 0, BLOCK_TYPE_WATER, 0, 0, 0, 0, "Water", "water", 1.0, 1.0 },
	{ 9, 0, BLOCK_TYPE_WATER, 0, 0, 0, 0, "Water", "water", 1.0, 1.0 },
	{ 10, 0, BLOCK_TYPE_CUBE, 1, 0, 0, 0, "Lava", "lava", 0.0, 1.0, 1.0 },
	{ 11, 0, BLOCK_TYPE_CUBE, 1, 0, 0, 0, "Lava", "lava", 0.0, 1.0, 1.0 },
	{ 12, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sand", "sand", 0.0, 1.0, 1.0 },
	{ 13, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Gravel", "gravel", 0.0, 1.0, 1.0 },
	{ 14, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Ore Gold", "oreGold", 0.0, 1.0, 1.0 },
	{ 15, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Ore Iron", "oreIron", 0.0, 1.0, 1.0 },
	{ 16, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Ore Coal", "oreCoal", 0.0, 1.0, 1.0 },
	{ 17, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Oak wood", "tree_side", 0.0, 1.0, 1.0 },
	{ 17, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Spruce wood", "tree_spruce", 0.0, 1.0, 1.0 },
	{ 17, 2, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Birch wood", "tree_birch", 0.0, 1.0, 1.0 },
	{ 17, 3, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Jungle wood", "tree_jungle", 0.0, 1.0, 1.0 },
	{ 17, 16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Log", "tree_top", 0.0, 1.0, 1.0 },
	{ 18, 0, BLOCK_TYPE_LEAVES, 0, 1, 1, 0x111111, "Oak leaves", "leaves", 0.0, 1.0, 1.0 },
	{ 18, 1, BLOCK_TYPE_LEAVES, 0, 1, 1, 0x111111, "Spruce leaves", "leaves_spruce", 0.0, 1.0, 1.0 },
	{ 18, 2, BLOCK_TYPE_LEAVES, 0, 1, 1, 0x111111, "Birch leaves", "leaves", 0.0, 1.0, 1.0 },
	{ 18, 3, BLOCK_TYPE_LEAVES, 0, 1, 1, 0x111111, "Jungle leaves", "leaves_jungle", 0.0, 1.0, 1.0 },
	{ 19, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sponge", "sponge", 0.0, 1.0, 1.0 },
	{ 20, 0, BLOCK_TYPE_CUBE, 0, 1, 1, 0, "Glass", "glass", 0.0, 1.0, 1.0 },
	{ 21, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Ore Lapis", "oreLapis", 0.0, 1.0, 1.0 },
	{ 22, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Block Lapis", "blockLapis", 0.0, 1.0, 1.0 },
//	{ 23, 0, 1, 1, 1, 1, 0, "Dispenser", "Dispenser", 0.0, 1.0, 1.0 },
	{ 24, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_side", 0.0, 1.0, 1.0 },
	{ 24, 16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_top", 0.0, 1.0, 1.0 },
	{ 24, 32, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_bottom", 0.0, 1.0, 1.0 },
	{ 24, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_carved", 0.0, 1.0, 1.0 },
	{ 24, 17, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_top", 0.0, 1.0, 1.0 },
	{ 24, 33, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_bottom", 0.0, 1.0, 1.0 },
	{ 24, 2, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_smooth", 0.0, 1.0, 1.0 },
	{ 24, 18, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_top", 0.0, 1.0, 1.0 },
	{ 24, 34, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Sandstone", "sandstone_bottom", 0.0, 1.0, 1.0 },
//	{ 25, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Note Block", "Note_Block", 0.0, 1.0, 1.0 }, 
//	{ 26, 0, 1, 1, 1, 1, 0, "Bed", "Bed", 0.0, 1.0, 1.0 },
	{ 27, 0, 1, 1, 0, 1, 0, "Powered Rail", "goldenRail", 0.0, 1.0, 1.0 },
	{ 27, 1, 1, 1, 0, 1, 0, "Powered Rail", "goldenRail_powered", 0.0, 1.0, 1.0 },
	{ 28, 0, BLOCK_TYPE_CUBE, 1, 0, 1, 0, "Activator Rail", "activatorRail", 0.0, 1.0, 1.0 },
	{ 28, 1, BLOCK_TYPE_CUBE, 1, 0, 1, 0, "ActivatorRail Powered", "activatorRail_powered", 0.0, 1.0, 1.0 },
//	{ 29, 0, 1, 1, 1, 1, 0, "Sticky Piston", "Sticky Piston", 0.0, 1.0, 1.0 },
	{ 30, 0, BLOCK_TYPE_CUBE, 1, 0, 1, 0, "Cobweb", "web", 0.0, 1.0, 1.0 },
	{ 31, 1, BLOCK_TYPE_GRASS, 0, 0, 1, 0x111111, "Tall Grass", "tallgrass", 0.0, 1.0, 1.0 },
	{ 31, 2, BLOCK_TYPE_GRASS, 0, 0, 1, 0, "Fern", "fern", 0.0, 1.0, 1.0 },
	{ 31, 0, BLOCK_TYPE_GRASS, 0, 0, 1, 0, "Deadbush", "deadbush", 0.0, 1.0, 1.0 },
	
	{ 35, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_0", 0.0, 1.0, 1.0 },
	{ 35, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_1", 0.0, 1.0, 1.0 },
	{ 35, 2, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_2", 0.0, 1.0, 1.0 },
	{ 35, 3, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_3", 0.0, 1.0, 1.0 },
	{ 35, 4, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_4", 0.0, 1.0, 1.0 },
	{ 35, 5, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_5", 0.0, 1.0, 1.0 },
	{ 35, 6, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_6", 0.0, 1.0, 1.0 },
	{ 35, 7, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_7", 0.0, 1.0, 1.0 },
	{ 35, 8, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_8", 0.0, 1.0, 1.0 },
	{ 35, 9, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_9", 0.0, 1.0, 1.0 },
	{ 35, 10, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_10", 0.0, 1.0, 1.0 },
	{ 35, 11, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_11", 0.0, 1.0, 1.0 },
	{ 35, 12, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_12", 0.0, 1.0, 1.0 },
	{ 35, 13, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_13", 0.0, 1.0, 1.0 },
	{ 35, 14, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_14", 0.0, 1.0, 1.0 },
	{ 35, 15, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Wool", "cloth_15", 0.0, 1.0, 1.0 },

	{ 37, 0, BLOCK_TYPE_GRASS, 0, 0, 1, 0, "Dandelion", "flower", 0.0, 1.0, 1.0 },
	{ 38, 0, BLOCK_TYPE_GRASS, 0, 0, 1, 0, "Rose", "rose", 0.0, 1.0, 1.0 },
	{ 39, 0, BLOCK_TYPE_GRASS, 0, 0, 1, 0, "Brown Mushroom", "mushroom_brown", 0.0, 1.0, 1.0 },
	{ 41, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Golden Block", "blockGold", 0.0, 1.0, 1.0 },
	{ 42, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Block", "blockIron", 0.0, 1.0, 1.0 },	
	
	{ 43, 0, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Stone Slab", "stoneslab_side", 0.0, 1.0, 1.0 },
	{ 43, 0+16, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Stone Slab", "stoneslab_top", 0.0, 1.0, 1.0 },
	{ 43, 1, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Sandstone Slab", "sandstone_side", 0.0, 1.0, 1.0 },
	{ 43, 1+16, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Sandstone Slab", "sandstone_top", 0.0, 1.0, 1.0 },
	{ 43, 1+32, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Sandstone Slab", "sandstone_bottom", 0.0, 1.0, 1.0 },
	{ 43, 2, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Wooden Slab", "wood", 0.0, 1.0, 1.0 },
	{ 43, 3, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Cobblestone Slab", "stonebrick", 0.0, 1.0, 1.0 },
	{ 43, 4, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Brick Slab", "brick", 0.0, 1.0, 1.0 },
	{ 43, 5, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Stonebrick Smooth Slab", "stonebricksmooth", 0.0, 1.0, 1.0 },
	{ 43, 6, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Nether Brick Slab", "netherBrick", 0.0, 1.0, 1.0 },
	{ 43, 7+0, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Quartzblock Slab", "quartzblock_side", 0.0, 1.0, 1.0 },
	{ 43, 7+16, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Quartzblock Slab", "quartzblock_top", 0.0, 1.0, 1.0 },
	{ 43, 7+32, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Quartzblock Slab", "quartzblock_bottom", 0.0, 1.0, 1.0 },
	{ 43, 8, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Stone Slab", "stoneslab_top", 0.0, 1.0, 1.0 },
	{ 43, 9, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Sandstone Smooth Slab", "sandstone_smooth", 0.0, 1.0, 1.0 },
	{ 43, 9+16, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Sandstone Smooth Slab", "sandstone_top", 0.0, 1.0, 1.0 },
	{ 43, 9+32, BLOCK_TYPE_DOUBLE_SLAB, 1, 1, 1, 0, "Double Sandstone Smooth Slab", "sandstone_bottom", 0.0, 1.0, 1.0 },
	
	{ 44, 0, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Stone Slab", "stoneslab_side", 0.0, 0.5, 1.0 },
	{ 44, 0+16, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Stone Slab", "stoneslab_top", 0.0, 0.5, 1.0 },
	{ 44, 1, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Sandstone Slab", "sandstone_side", 0.0, 0.5, 1.0 },
	{ 44, 1+16, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Sandstone Slab", "sandstone_top", 0.0, 0.5, 1.0 },
	{ 44, 1+32, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Sandstone Slab", "sandstone_bottom", 0.0, 0.5, 1.0 },
	{ 44, 2, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Wooden Slab", "wood", 0.0, 0.5, 1.0 },
	{ 44, 3, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Cobblestone Slab", "cobblestone", 0.0, 0.5, 1.0 },
	{ 44, 4, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Brick Slab", "brick", 0.0, 0.5, 1.0 },
	{ 44, 5, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Stonebrick Smooth Slab", "stonebricksmooth", 0.0, 0.5, 1.0 },
	{ 44, 6, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Nether Brick Slab", "netherBrick", 0.0, 0.5, 1.0 },
	{ 44, 7+0, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Quartzblock Slab", "quartzblock_side", 0.0, 0.5, 1.0 },
	{ 44, 7+16, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Quartzblock Slab", "quartzblock_top", 0.0, 0.5, 1.0 },
	{ 44, 7+32, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Quartzblock Slab", "quartzblock_bottom", 0.0, 0.5, 1.0 },
	{ 44, 8, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Stone Slab", "stoneslab_top", 0.0, 0.5, 1.0 },
	{ 44, 9, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Sandstone Smooth Slab", "sandstone_smooth", 0.0, 0.5, 1.0 },
	{ 44, 9+16, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Sandstone Smooth Slab", "sandstone_top", 0.0, 0.5, 1.0 },
	{ 44, 9+32, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Sandstone Smooth Slab", "sandstone_bottom", 0.0, 0.5, 1.0 },	
	{ 45, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Brick", "brick", 0.0, 1.0, 1.0 },
	{ 46, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "TNT", "tnt_side", 0.0, 1.0, 1.0 },
	{ 46, 16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "TNT", "tnt_top", 0.0, 1.0, 1.0 },
	{ 46, 32, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "TNT", "tnt_bottom", 0.0, 1.0, 1.0 },
	{ 47, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Bookshelf", "bookshelf", 0.0, 1.0, 1.0 },
	{ 48, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Moss Stone", "stoneMoss", 0.0, 1.0, 1.0 },
	{ 49, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Obsidian", "obsidian", 0.0, 1.0, 1.0 },
	{ 50, 0, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Torch", "torch", 0.0, 1.0, 0.125 },
	
	{ 51, 0, BLOCK_TYPE_GRASS, 1, 1, 1, 0, "Fire", "fire_0", 0.0, 1.0, 1.0 },
	{ 51, 1, BLOCK_TYPE_GRASS, 1, 1, 1, 0, "Fire", "fire_1", 0.0, 1.0, 1.0 },	
	
	{ 52, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Mob Spawner", "mobSpawner", 0.0, 1.0, 1.0 },
	{ 53, 0, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Wood Stairs", "wood", 0.0, 1.0, 1.0 },
	{ 53, 1, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Wood Stairs", "wood", 0.0, 1.0, 1.0 },
	{ 53, 2, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Wood Stairs", "wood", 0.0, 1.0, 1.0 },
	{ 53, 3, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Wood Stairs", "wood", 0.0, 1.0, 1.0 },

	{ 54, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Chest", "chest", 0.0, 0.875, 1.0 },
	
	{ 55, 0, BLOCK_TYPE_SLAB, 1, 1, 1, 0, "Redstone Dust Cross", "redstoneDust_cross", 0.0, 0.125, 1.0 },
	{ 56, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Diamond Ore", "oreDiamond", 0.0, 1.0, 1.0 },
	{ 57, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Diamond Block", "blockDiamond", 0.0, 1.0, 1.0 },
	
	{ 58, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Workbench", "workbench_side", 0.0, 1.0, 1.0 },
	{ 58, 16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Workbench", "workbench_top", 0.0, 1.0, 1.0 },
	{ 58, 32, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Workbench", "wood", 0.0, 1.0, 1.0 },
	{ 58, 64, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Workbench", "workbench_front", 0.0, 1.0, 1.0 },
	
	{ 59, 0, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_0", 0.0, 1.0, 1.0 },
	{ 59, 1, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_1", 0.0, 1.0, 1.0 },
	{ 59, 2, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_2", 0.0, 1.0, 1.0 },
	{ 59, 3, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_3", 0.0, 1.0, 1.0 },
	{ 59, 4, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_4", 0.0, 1.0, 1.0 },
	{ 59, 5, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_5", 0.0, 1.0, 1.0 },
	{ 59, 6, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_6", 0.0, 1.0, 1.0 },
	{ 59, 7, BLOCK_TYPE_CROPS, 1, 1, 1, 0, "Crops", "crops_7", 0.0, 1.0, 1.0 },
	
	{ 60, 0   , BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "dirt", 0.0, 1.0, 1.0 },
	{ 60, 0+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_dry", 0.0, 0.875, 1.0 },
	{ 60, 1+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 2+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 3+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 4+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 5+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 6+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 7+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	{ 60, 8+16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Farmland", "farmland_wet", 0.0, 0.875, 1.0 },
	
	{ 61, 0 , BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Furnace", "furnace_side", 0.0, 1.0, 1.0 },
	{ 61, 16, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Furnace", "furnace_top", 0.0, 1.0, 1.0 },
	{ 61, 32, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Furnace", "cobblestone", 0.0, 1.0, 1.0 },
	{ 61, 64, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Furnace", "furnace_front", 0.0, 1.0, 1.0 },
	
//	{ 62, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "wood", "wood", 0.0, 1.0, 1.0 },
//	{ 63, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "wood", "wood", 0.0, 1.0, 1.0 },
//	{ 64, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "wood", "wood", 0.0, 1.0, 1.0 },

	{ 65, 0, BLOCK_TYPE_LADDER, 1, 1, 1, 0, "Ladder", "ladder", 0.0, 1.0, 0.125 },
	
	{ 66, 0, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 1, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 2, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 3, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 4, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 5, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 6, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 7, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 8, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	{ 66, 9, BLOCK_TYPE_RAIL, 0, 0, 1, 0, "Rail", "rail", 0.0, 1.0, 1.0 },
	
	{ 67, 0, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Cobblestone Stairs", "stonebrick", 0.0, 1.0, 1.0 },
	{ 67, 1, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Cobblestone Stairs", "stonebrick", 0.0, 1.0, 1.0 },
	{ 67, 2, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Cobblestone Stairs", "stonebrick", 0.0, 1.0, 1.0 },
	{ 67, 3, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Cobblestone Stairs", "stonebrick", 0.0, 1.0, 1.0 },
//	{ 68, 0, BLOCK_TYPE_STAIRS, 1, 1, 1, 0, "Cobblestone", "cobblestone", 0.0, 1.0, 1.0 },
	{ 69, 0, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 1, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 2, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 3, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 4, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 5, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 6, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 7, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 69, 8, BLOCK_TYPE_TORCH, 1, 1, 1, 0, "Lever", "lever", 0.0, 1.0, 0.125 },
	{ 70, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Pressure Plate Stone", "stone", 0.0, 0.125, 1.0 },
	{ 71, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_lower", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 71, 1, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Iron Door", "doorIron_upper", 0.0, 0.125, 1.0 },
	{ 72, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0,"Pressure Plate Wood", "wood", 0.0, 0.125, 1.0 },
	
	
	
	{ 98, 0, BLOCK_TYPE_CUBE, 1, 1, 1, 0, "Stonebrick", "stonebricksmooth", 0.0, 1.0, 1.0 },
	

};

static Material* _materials_id_data[256][256] = { { NULL } };
static u32 _materials_color[256][256] = { 0x00000000 };

static Material _materials[sizeof(block_props)/sizeof(BlockProps)];
static bool _materials_initialized = false;

static void str_format(char* dst, const char* path, const char* str, const char* ext){
	char tmp[1024];
	char* dst0 = dst;
	while(*str){
		if(*str == ' '){
			*dst = '_';
		}else{
			*dst = *str;
		}
		str++;
		dst++;
	}
	*dst = 0x0;
	strcpy(tmp, path);
	strcat(tmp, dst0);
	strcat(tmp, ext);
	strcpy(dst0, tmp);
}

void Material::_materials_init(Client* client){
	u32 i, j, k, x, y, x2, y2, nAnims;
	float u, v, w, h;
	bool create;
	char path[1024];
	ge_Image* tex = NULL;

	if(_materials_initialized){
		return;
	}
	gePrintDebug(0, "Material::_materials_init()\n");
	_materials_initialized = true;

	client->res.terrain = geCreateSurface(4096, 4096, 0x00000000);

	geDebugCritical(false);
	for(i=0; i<sizeof(_materials)/sizeof(Material); i++){
		u32 color = 0x00000000;
		nAnims = 1;
		tex = NULL;
		create = true;
		for(j=0; j<i; j++){
			if(!strcmp(block_props[i].name, block_props[j].texture)){
				create = false;
				break;
			}
		}
		if(create){
			str_format(path, "resources/textures/blocks/", block_props[i].texture, ".png");
			tex = geLoadImage(path);
			if(tex){
				str_format(path, "resources/textures/blocks/", block_props[i].texture, ".txt");
				int total_height = 0;
				int table[1024] = { 0 };
				ge_File* fp = geFileOpen(path, GE_FILE_MODE_READ | GE_FILE_MODE_BINARY);
				if(fp){
					char buf[1024];
					char buf2[512];
					k = 0;
					while(geFileGets(fp, buf, 1024)){
						strncpy(buf2, buf, 514);
						if(strchr(buf2, '*')){
							strchr(buf2, '*')[0] = 0x0;
						}
						int n0 = atoi(buf2);
						int n1 = 1;
						if(strchr(buf, '*')){
							strncpy(buf2, &buf[strlen(buf2)+1], 514);
							n1 = atoi(buf2);
						}
						for(; n1>0; n1--, k++, total_height++){
							table[k] = n0;
						}
					}
					geFileClose(fp);
				}else
				if(tex->height > tex->width){
					total_height = std::max(1, tex->height / tex->width);
					for(k=0; k<total_height; k++){
						table[k] = k;
					}
				}else{
					total_height = 1;
				}

				bool ok = false;
				bool cont = true;
				for(y=0; y<client->res.terrain->height && !ok; y+=16){
					for(x=0; x<client->res.terrain->width && !ok; x+=16){
						cont = false;
						for(y2=0; y2<tex->width*total_height && !ok; y2++){
							for(x2=0; x2<tex->width && !ok; x2++){
								if(client->res.terrain->data[(y+y2)*client->res.terrain->textureWidth + x+x2] != 0x00000000){
									cont = true;
									y2 = 2147483647;
									break;
								}
							}
						}
						if(!cont){
							ok = true;
							y -= 16;
							break;
						}
					}
				}
				//geBlitImageToImage(x, y, tex, 0, 0, tex->width, tex->height, client->res.terrain);
				for(k=0; k<total_height; k++){
					geBlitImageToImage(x, y+k*tex->width, tex, 0, tex->width*table[k], tex->width, tex->width, client->res.terrain);
				}
				u = ((float)x) / ((float)client->res.terrain->width);
				v = ((float)y) / ((float)client->res.terrain->height);
				w = ((float)tex->width) / ((float)client->res.terrain->width);
				h = ((float)tex->width) / ((float)client->res.terrain->height);
				nAnims = total_height;

				u32 r = 0;
				u32 g = 0;
				u32 b = 0;
				u32 a = 0;
				u32 N = 0;
				for(y=0; y<tex->height; y++){
					for(x=0; x<tex->width; x++){
						u32 c = tex->data[y*tex->textureWidth + x];
						r += R(c);
						g += G(c);
						b += B(c);
						a += A(c);
						N++;
					}
				}
				if(N != 0){
					r /= N;
					g /= N;
					b /= N;
					a /= N;
				}
				color = RGBA(r, g, b, a);
			}
		}else{
			u = _materials[j].renderProps.u;
			v = _materials[j].renderProps.v;
			w = _materials[j].renderProps.w;
			h = _materials[j].renderProps.h;
			nAnims = _materials[j].renderProps.animations;
			color = _materials_color[_materials[j].id][_materials[j].data];
		}

		_materials[i].id = block_props[i].id;
		_materials[i].data = block_props[i].data;
		_materials[i].name = strdup(block_props[i].name);
		_materials[i].solid = block_props[i].solid;
		_materials[i].collidable = block_props[i].collidable;
		_materials[i].clickable = block_props[i].clickable;
		_materials[i].biomeColored = block_props[i].biome_colored;
		_materials[i].renderProps.blockType = block_props[i].type;
		_materials[i].renderProps.u = u;
		_materials[i].renderProps.v = v;
		_materials[i].renderProps.w = w;
		_materials[i].renderProps.h = h;
		_materials[i].renderProps.specular = block_props[i].specular;
		_materials[i].renderProps.animations = nAnims;
		_materials_id_data[_materials[i].id][_materials[i].data] = &_materials[i];
		_materials_color[_materials[i].id][_materials[i].data] = color;
		printf("%s anims : %d\n", _materials[i].name, _materials[i].renderProps.animations);
	}
	geDebugCritical(true);

	geUpdateImage(client->res.terrain);


	int aaa = 0;
	while(1){
		geReadKeys(client->keys);
		if(client->keys->pressed[GEK_ENTER]){
			break;
		}
		if(geKeysToggled(client->keys, 'S')){
			aaa = !aaa;
		}
		geClearColor(0xFF303030);
		geClearScreen();
		if(aaa){
			geFillRectScreen(0, 0, geGetContext()->width, geGetContext()->height, 0xFF000000);
			geDrawImage(0, 0, client->res.terrain);
		}else{
			geFillRectScreen(0, 0, geGetContext()->height, geGetContext()->height, 0xFF000000);
			geDrawImageStretched(0, 0, client->res.terrain, geGetContext()->height, geGetContext()->height);
		}
		geFontPrintfScreen(geGetContext()->height+20, 20, client->res.font, 0xFFFFFFFF, "Size :");
		geFontPrintfScreen(geGetContext()->height+25, 45, client->res.font, 0xFFFFFFFF, "%d x %d", client->res.terrain->width, client->res.terrain->height);
		geFontPrintfScreen(geGetContext()->height+20, 70, client->res.font, 0xFFFFFFFF, "([S] : toggle size mode)");
		geSwapBuffers();
	}

}

Material::Material(){
	id = 0;
	data = 0;
	name = NULL;
}

Material::Material(const Material* m){
	id = m->id;
	data = m->data;
	name = strdup(m->name);
	solid = m->solid;
	biomeColored = m->biomeColored;
	renderProps = m->renderProps;
}

Material::Material(const Material& m){
	id = m.id;
	data = m.data;
	name = strdup(m.name);
	solid = m.solid;
	biomeColored = m.biomeColored;
	renderProps = m.renderProps;
}

Material::~Material(){
	if(name){
		free(name);
	}
}

unsigned char Material::getId(){
	return id;
}

void Material::setId(unsigned char _id){
	id = _id;
}

unsigned char Material::getData(){
	return data;
}

void Material::setData(unsigned char _data){
	data = _data;
}

bool Material::isSolid(){
	return solid;
}

int Material::isBiomeColored(){
	return biomeColored;
}

void Material::setBiomeColored(int c){
	biomeColored = c;
}

bool Material::isClickable(){
	return clickable;
}

void Material::setClickable(bool c){
	clickable = c;
}

bool Material::isCollidable(){
	return collidable;
}

void Material::setCollidable(bool c){
	collidable = c;
}

Material* Material::FindByName(const char* _name){
	for(u32 i=0; i<sizeof(_materials)/sizeof(Material); i++){
		if(!strcmp(_materials[i].name, _name)){
			return &_materials[i];
		}
	}
	return NULL;
}

Material* Material::FindById(const unsigned char _id){
	Material* ret = _materials_id_data[_id][0];
	if(!ret){
	//	ret = _materials_id_data[1][0];
	}
	return ret;
}

Material* Material::FindByIdData(const unsigned char _id, const unsigned char _data){
	Material* ret = _materials_id_data[_id][_data];
	if(!ret){
	//	ret = _materials_id_data[1][0];
	}
	return ret;
}

Material* Material::GetAll(){
	return _materials;
}

u32 Material::GetBlockColor(u8 id, u8 data){
	return _materials_color[id][data];
}
